package com.es.util.mail;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.es.pay.mailAndMsg.MailAndMsgBiz;
import com.es.util.msg.SendMessage;

public class SendMsg{
	private static ExecutorService service = Executors.newFixedThreadPool(10);
	private String mailMsg = "";

	public static void sendMailForSalary(ArrayList<HashMap<String,String>> msg) throws IOException{
		if(null!=msg){
			final ArrayList<HashMap<String,String>> sendMsg = msg;
			service.execute(new Runnable() {
				public void run() {
					MailInfo mailinfo;
					try {
						mailinfo = new MailInfo();
					
			        String [] toAddress= new String[sendMsg.size()];
			        int i=0;
			        for(HashMap<String,String> map : sendMsg){
			        	if(map.get("emp_mail")!=null&&!"".equals(map.get("emp_mail")))
			        		toAddress[i++] = map.get("emp_mail");
			        }
			        String[] toAddress1= new String[i];

			        for(int j=0;j<i;j++){
			        	toAddress1[j]=toAddress[j];
			        }
			        mailinfo.setToAddress(toAddress1); 
			        
			        mailinfo.setSubject("工资发放通知"); 
			        String contentStart = "<a href='#'>";
			        String contentEnd = "</a>";
			        String content = "";
			        content += " 您好，\n";
			        content += " 您的工资已经发放，请登录系统查看!";
			        
			        /*mailinfo.setContent(contentStart + content + contentEnd);//网页内容   
			*/      mailinfo.setContent(content);
			        SendMail sm=new SendMail();   
			        sm.sendHtmlMail(mailinfo);
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}  
				}
			});			
		}
	}
	
	public static void sendMsgForSalary(ArrayList<HashMap<String,String>> msg) throws IOException{
		if(null!=msg){
			final ArrayList<HashMap<String,String>> sendMsg = msg;
			service.execute(new Runnable() {
				public void run() {
					try {
			        	ArrayList<HashMap<String,String>> result  = SendMessage.getInstance().doIt(sendMsg);
			        	if(result.size()>0){
			        		MailAndMsgBiz.updateMsgResult(result);
			        	}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
					
				}
			});	
		}
	}
}